package com.boolib.shopadmin.web;

import com.boolib.commons.Const;
import com.boolib.commons.entity.ServerResponse;
import com.boolib.pojo.ShopCategory;
import com.boolib.pojo.SysUser;
import com.boolib.service.ICategoryService;
import com.boolib.shopadmin.config.shiro.commons.ShiroUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RequiresAuthentication
@RestController
@RequestMapping("/admin/category")
public class CategoryController {


    @Autowired
    private ICategoryService iCategoryService;


    @RequestMapping("/add")
    public ServerResponse addCategory(ShopCategory shopCategory){

        Subject subject  =  SecurityUtils.getSubject();

        SysUser sysUser = (SysUser) subject.getPrincipal();

        return  iCategoryService.addCategory(shopCategory,sysUser.getUsername());
    }



    @RequestMapping("/normal")
    public ServerResponse selectCategoryNormal(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){

        return  iCategoryService.selectAllNormal(pageNum,pageSize);
    }




    @RequestMapping("/abnormal")
    public ServerResponse selectCategoryAbnormal(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){

        return  iCategoryService.selectAllAbnormal(pageNum,pageSize);
    }


    @RequestMapping("/update")
    public ServerResponse updateCategory(ShopCategory shopCategory){
        SysUser sysUser = ShiroUtils.getUser();
        return  iCategoryService.updateCategory(shopCategory , sysUser.getUsername());
    }




    @RequestMapping("/forbid")
    public ServerResponse forbid(Integer categoryId){
        SysUser sysUser = ShiroUtils.getUser();
        return  iCategoryService.forbid(categoryId,sysUser.getUsername());
    }


    @RequestMapping("/recover")
    public ServerResponse recover(Integer categoryId){
        SysUser sysUser = ShiroUtils.getUser();
        return  iCategoryService.recover(categoryId,sysUser.getUsername());
    }







}
